#include <RenderSubSystem/DrawlistNode.h>
#include <RenderSubSystem/cvIRender.h>
#include <RenderSubSystem/Renderinglayer.h>

namespace cvRenderInterface
{

	DrawlistNode::DrawlistNode()
		: m_draworder(-1.0), m_drawgroup(0), m_lockedtransfer(false)
	{
		m_layer = IRenderer::getActiveLayer();
	}

	DrawlistNode::~DrawlistNode()
	{}

	void DrawlistNode::setDrawPriority(int level)
	{
		const float depthstep = (2.0f / 65536.0f);	// todo: draworderstep value should be get from GL.
		m_draworder = -1.0f + depthstep * level;
		m_layer->triggerZSort();
	}

	float DrawlistNode::drawPriority() const	{ return m_draworder; }

	void DrawlistNode::setDrawGroup(size_t id)
	{
		m_drawgroup = id;
	}

	size_t DrawlistNode::drawGroup() const	{ return m_drawgroup; }

	void DrawlistNode::lockTransfer(bool enable)	{ m_lockedtransfer = enable; }

	bool compare_drawnodes(const DrawlistNode & left, const DrawlistNode & right)
	{
		return left.drawPriority() < right.drawPriority();
	}
};
